<template>
	<view class="container">
		<view class="df jsb ac f32 bottom-line pl20 pr20 pt10 pb10 h60">
			<view class="w30 df ac">
				<imageIcon :value="iconCal"></imageIcon>
				<view class="ml20">填报周期</view>
			</view>
			<view class="w70 df jse ac tr">
				<text>{{ detailInfo.dailyDateStr || '-' }}</text>
			</view>
		</view>
		<view class="bottom-line pb20">
			<view
				class="back-c6 border-4 ml20 mr20 mt20 pl10"
				v-if="
					detailInfo.scheduleCount > 0 || detailInfo.actionCount > 0
				"
				@tap="goViewSchedule"
			>
				<text class="f28">
					本{{
						detailInfo.type === 0
							? '日报'
							: detailInfo.type === 1
							? '周报'
							: '月报'
					}}关联了
					<text v-if="detailInfo.scheduleCount > 0">
						<text class="active-color">{{
							detailInfo.scheduleCount
						}}</text>
						个日程
					</text>
					<text v-if="detailInfo.actionCount > 0">
						<text class="active-color">{{
							detailInfo.actionCount
						}}</text>
						个行动措施，
					</text>
					完成度{{ detailInfo.finishDegree }}
				</text>
			</view>
			<view class="df ac pt20 pb20 f32 pl20 pr20">
				<imageIcon :value="iconDetail" width="34rpx"></imageIcon>
				<view class="ml20">填写内容</view>
			</view>
			<view>
				<view
					class="mb30 bottom-line"
					v-for="(item, index) in detailInfo.details"
					:key="index"
				>
					<view class="pl20 pr20">
						<view class="df jsb pb20">
							<view class="f32 word-break qus-title"
								>{{ index + 1 }}.{{ item.title }}</view
							>
							<scheduleBtn
								:dailyId="detailInfo.id"
								:journalDetailId="item.id"
							></scheduleBtn>
						</view>
						<view v-show="(item.unfold && !isPreview) || isPreview">
							<view
								class="flex-start flex-wrap pb20"
								v-if="
									item.selectedWorkContentLabelVOList &&
									item.selectedWorkContentLabelVOList.length
								"
							>
								<view
									class="tag-view tag-view-active mr10 mt10 rel"
									v-for="(
										tag, tagIndex
									) in item.selectedWorkContentLabelVOList"
									:key="tagIndex"
									>{{ tag.labelName }}</view
								>
							</view>
							<view
								class="pl20 pr20 pb20"
								v-if="
									item.content ||
									(item.urls && item.urls.length) ||
									(item.voice && item.voice.length)
								"
							>
								<view
									v-if="
										item.recongtionContent &&
										item.recongtionContent.length
									"
									class="word-break f28 g6b"
								>
									<block
										v-for="(
											node, nodeIdx
										) in item.recongtionContent"
										:key="nodeIdx"
									>
										<block v-if="node.node === 'element'">
											<block v-if="node.tag === 'span'">
												<block
													v-for="(
														node, no
													) in node.nodes"
													:key="no"
												>
													<text
														v-if="
															node.node === 'text'
														"
														class="line-font"
														@tap="
															clickInfo(
																node.text,
																item.journalId,
																item.id
															)
														"
														>{{ node.text }}</text
													>
												</block>
											</block>
											<block v-if="node.tag === 'br'"
												><text>\n</text></block
											>
										</block>
										<block v-if="node.node === 'text'">{{
											node.text
										}}</block>
									</block>
								</view>
								<view class="f28 word-break g6b" v-else>{{
									item.content
								}}</view>
								<view
									class="mt30"
									v-if="item.urls && item.urls.length"
									><show-media :value="item.urls"></show-media
								></view>
								<view
									class="mt30"
									v-if="item.voice && item.voice.length"
								>
									<!-- <view v-for="(audio, auIndex) in item.voice" :key="auIndex" class="mb20"> -->
									<!-- <diy-audio :audio-time="audio.duration" :file="audio.url" :voice-text="audio.text" :width="200"></diy-audio> -->
									<!-- </view> -->
									<diy-audioMultiple
										:audioArry="item.voice"
										:width="200"
									></diy-audioMultiple>
								</view>
							</view>
							<view v-if="!isPreview" class="mt10 top-line pt20">
								<view class="flex-between">
									<view
										><image
											:src="packUpImg"
											class="mb10 pack-img"
											@tap="unfoldImgClick(index, false)"
										></image
									></view>
									<view
										class="df jse ac f32 pb20 w-flex"
										:class="
											(detailType === 'detail' &&
												item.showReply &&
												item.replies &&
												item.replies.length) ||
											(detailType === 'approval' &&
												item.replies &&
												item.replies.length)
												? 'reply-line'
												: ''
										"
									>
										<view
											@click="clickLikeNum(item, index)"
											class="df ac f32 ml20"
										>
											<imageIcon
												:value="
													item.likeStatus
														? zanCheck
														: zanNoCheck
												"
												width="34rpx"
											></imageIcon>
											<view class="ml10">
												{{
													item.likeStatus &&
													item.likeNum > 0 &&
													item.likeNum < 100
														? '已点赞+' +
														  item.likeNum
														: !item.likeStatus &&
														  item.likeNum > 0 &&
														  item.likeNum < 100
														? '点赞+' + item.likeNum
														: item.likeStatus &&
														  item.likeNum > 99
														? '已点赞99+'
														: !item.likeStatus &&
														  item.likeNum > 99
														? '点赞99+'
														: '点赞'
												}}
											</view>
										</view>
										<view
											@click="
												updateWeekStatusNum(item, index)
											"
											class="df ac f32"
										>
											<imageIcon
												:value="
													item.weekStatus
														? explosive2
														: explosive1
												"
												width="46rpx"
												height="46rpx"
											></imageIcon>
											<view class="ml10">
												{{
													item.weekStatus &&
													item.weekNum > 0 &&
													item.weekNum < 100
														? '已弱爆+' +
														  item.weekNum
														: !item.weekStatus &&
														  item.weekNum > 0 &&
														  item.weekNum < 100
														? '弱爆+' + item.weekNum
														: item.weekStatus &&
														  item.weekNum > 99
														? '已弱爆99+'
														: !item.weekStatus &&
														  item.weekNum > 99
														? '弱爆99+'
														: '弱爆'
												}}
											</view>
										</view>
										<!-- 		<view class="ml20 df ac f32" @tap="clickShowReply(index)" v-if="!showApproval">
									<imageIcon :value="item.showReply && item.replies && item.replies.length ? chatCheck : chatNoCheck" height="30rpx" style="padding-top: 2rpx"></imageIcon>
									<view class="ml10">{{ !item.replies || !item.replies.length ? '暂无回复' : item.replyTitle }}</view>
								</view> -->
										<view
											class="ml20 df ac f32"
											:class="{
												'active-color':
													item.showApproval,
											}"
											@tap="clickReply(index)"
											v-if="showApproval"
										>
											<imageIcon
												:value="
													item.showApproval
														? chatCheck
														: chatNoCheck
												"
												height="30rpx"
												style="padding-top: 2rpx"
											></imageIcon>
											<view class="ml10">{{
												item.replies &&
												item.replies.length
													? '已回复'
													: '回复'
											}}</view>
										</view>
									</view>
								</view>
								<view
									class="mt20 f32"
									v-if="
										(detailType === 'detail' &&
											item.showReply &&
											item.replies &&
											item.replies.length) ||
										detailType === 'approval'
									"
								>
									<view
										class="f28"
										v-if="
											item.replies && item.replies.length
										"
										>全部回复</view
									>
									<view
										v-for="reply in item.replies"
										:key="reply.id"
										class="df mt20 reply-line"
									>
										<view class="reply-avatar"
											><image
												:src="avatarImg"
												class="avatar-img"
											></image
										></view>
										<view class="ml10 f24 w80">
											<view
												v-if="reply.userName"
												class="pl20"
												>{{ reply.userName }}</view
											>
											<view
												v-if="reply.content"
												class="flex-1 pl20"
												>{{ reply.content }}</view
											>
											<view
												v-if="reply.voiceUrl"
												class="ml20"
											>
												<diy-audio
													:file="reply.voiceUrl"
													:audio-time="
														reply.voiceDuration
													"
													:voice-text="
														reply.voiceText
													"
													:width="200"
												></diy-audio>
											</view>
											<view
												class="rp-time f24 pl20 pb20"
												v-if="reply.gmtCreate"
												>{{
													reply.gmtCreate
														.slice(5, 19)
														.replace(/-/g, '/')
												}}</view
											>
										</view>
									</view>
									<view
										v-if="
											showApproval &&
											detailInfo.readStatus !== 3 &&
											item.replies &&
											item.replies.length
										"
										class="mt20 pb20"
									>
										<button
											class="reply-button w40"
											@tap="clickReply(index)"
										>
											添加回复>
										</button>
									</view>
								</view>
								<view
									class="mt20 pb20"
									v-if="item.showApproval && showApproval"
								>
									<reply-input
										@input="replyInput"
										@record="replyRecord"
										:local-data="item"
									></reply-input>
									<view class="mt20"
										><button
											class="reply-button w40"
											@tap="submitReply(item, index)"
										>
											提交回复
										</button></view
									>
								</view>
							</view>
						</view>
						<view v-if="!item.unfold && !isPreview" class="tc"
							><image
								:src="unfoldImg"
								class="show-more"
								@tap="unfoldImgClick(index, true)"
							></image
						></view>
					</view>
				</view>
				<view class="pl20 pr20" v-if="!unfoldStatic && !isPreview">
					<view class="mt20 f32">
						<block v-if="detailInfo.type + 1 === 1">
							{{
								detailInfo.details &&
								detailInfo.details.length + 1
							}}、{{ nowDateStr }}运营数据分析（统计周期为{{
								detailInfo.type + 1 === 1 ? '前一天' : ''
							}}
							<view>{{ periodStr }}）</view>
						</block>
						<block v-else
							>{{
								detailInfo.details &&
								detailInfo.details.length + 1
							}}、{{ nowDateStr }}运营数据分析（统计周期为{{
								periodStr
							}}</block
						>
					</view>
					<view class="tc"
						><image
							:src="unfoldImg"
							class="show-more"
							@tap="unfoldStatic = true"
						></image
					></view>
					<view class="tc"
						><image
							:src="unfoldAllImg"
							class="show-more"
							@tap="showAllClick(true)"
						></image
					></view>
				</view>
				<view
					class="pl20 pr20"
					v-show="(unfoldStatic && !isPreview) || isPreview"
				>
					<staticHistogram
						:titleIndex="
							detailInfo.details && detailInfo.details.length + 1
						"
						:reportType="detailInfo.type + 1"
						:orderOperate="detailInfo.orderOperate"
						:showCharts="(unfoldStatic && !isPreview) || isPreview"
					></staticHistogram>
					<block
						v-if="
							detailInfo.content ||
							(detailInfo.voices && detailInfo.voices.length)
						"
					>
						<view class="mt20 lh60 b">数据情况分析：</view>
						<view class="detail-box mt20">
							<view class="mt20 f32">{{
								detailInfo.content || ''
							}}</view>
							<!-- 	<view class="mt20" v-for="(voice, voIdx) in detailInfo.voices" :key="voIdx">
								<diy-audio :file="voice.url" :audioTime="voice.duration" :voiceText="voice.text" :width="200"></diy-audio>
							</view> -->
							<diy-audioMultiple
								:audioArry="detailInfo.voices"
								:width="200"
							></diy-audioMultiple>
						</view>
					</block>
					<view v-if="!isPreview" class="mt20 tc"
						><image
							:src="packUpImg"
							class="mb10 pack-img"
							@tap="unfoldStatic = false"
						></image
					></view>
					<view
						v-if="!isPreview && unfoldStatic && !showAll"
						class="tc"
						><image
							:src="unfoldAllImg"
							class="show-more"
							@tap="showAllClick(true)"
						></image
					></view>
					<view v-if="!isPreview && showAll" class="mt20 tc"
						><image
							:src="packUpAllImg"
							class="mb10 show-more"
							@tap="showAllClick(false)"
						></image
					></view>
				</view>
			</view>
		</view>
		<!--可见成员-->
		<view class="bottom-line pl20 pr20">
			<showUserList
				:icon="iconKeJain"
				title="可见成员"
				:showBtn="detailInfo.auditorFlag ? true : false"
				@click="addUser(0)"
				:localdata="detailInfo.viewerUsers"
			></showUserList>
		</view>
		<!--审批人-->
		<view class="bottom-line pl20 pr20">
			<showUserList
				:icon="iconShenPi"
				title="审批人"
				:showBtn="detailInfo.auditorFlag ? true : false"
				@click="addUser(1)"
				:localdata="detailInfo.auditorUsers"
			></showUserList>
		</view>
		<view class="bottom-button-bd dsb" v-if="showBottom">
			<view class="df jsb" v-if="isPreview">
				<button class="default-button circle w45" @tap="backModify">
					返回修改
				</button>
				<button
					class="primary-button w45 linear"
					:disabled="isDisabled"
					@tap="$noMultipleClicks(submitSave, 2)"
				>
					确认提交
				</button>
			</view>
			<button
				class="primary-button linear ml20 mr20"
				v-if="!isPreview"
				@tap="goModifyReport"
			>
				修改
			</button>
		</view>
		<!-- 审批人可修改 -->
		<!-- 	<view class="bottom-button-bd dsb" v-if="detailInfo.auditorFlag && !showBottom">
			<button class="primary-button linear ml20 mr20" @tap="$noMultipleClicks(submitSave, 1)">修改</button>
		</view> -->
		<!-- 选择成员 -->
		<user-list
			ref="userRefs"
			:userList="userData"
			@search="searchUserList"
			@complete="updateUserList"
		></user-list>
	</view>
</template>

<script>
import userList from './compoents/userList/userList.vue'
import diyAudio from '@/subPackagesLog/components/diy-audio/diy-audio.vue'
import diyAudioMultiple from '@/subPackagesLog/components/diy-audioMultiple/diy-audioMultiple.vue'
import replyInput from '@/subPackagesLog/components/reply-input/reply-input.vue'
import staticHistogram from '@/subPackagesLog/pages/workLog/components/showStaticHistogram.vue'
import scheduleBtn from '@/subPackagesLog/pages/workLog/components/scheduleBtn.vue'
import imageIcon from '@/subPackagesLog/pages/workLog/components/imageIcon.vue'
import showUserList from '@/subPackagesLog/pages/workLog/components/showUserList.vue'
import HtmlToJson from '@/common/libs/html2json.js'
import avatarImg from '@/static/img/avatar.png'
import zanNoCheck from '@/static/img/zan-1.png'
import zanCheck from '@/static/img/zan-2.png'
import chatNoCheck from '@/static/img/chat-1.png'
import chatCheck from '@/static/img/chat-2.png'
import plusImg from '@/static/img/plus.png'
import iconDetail from './icon/tianxie-icon.png'
import iconCal from '@/static/img/icon-cal.png'
import iconKeJain from './icon/kejian-icon.png'
import iconShenPi from './icon/shenpi-icon.png'
import explosive1 from '@/static/img/explosive-1.png'
import explosive2 from '@/static/img/explosive-2.png'
export default {
	components: {
		diyAudio,
		diyAudioMultiple,
		replyInput,
		staticHistogram,
		scheduleBtn,
		imageIcon,
		showUserList,
		userList,
	},
	data() {
		return {
			explosive1,
			explosive2,
			iconDetail,
			iconCal,
			iconKeJain,
			iconShenPi,
			avatarImg,
			zanNoCheck,
			zanCheck,
			chatNoCheck,
			chatCheck,
			plusImg,
			detailType: 'detail',
			detailInfo: {},
			isPreview: false,
			loginUser: {},
			isDisabled: false,
			noClick: true,
			reportId: '',
			userId: '',
			replyData: {
				journalDetailId: '',
				content: '',
				voiceUrl: '',
				voiceDuration: 0,
				voiceText: '',
			},
			startHandler: {
				type: Function,
				default() {
					return (node) => {
						node.attr.class = null
						node.attr.style = null
					}
				},
			},
			endHandler: {
				type: Function,
				default: null,
			},
			imageProp: {
				type: Object,
				default() {
					return {
						mode: 'aspectFit',
						padding: 0,
						lazyLoad: false,
						domain: '',
					}
				},
			},
			chooseUserType: 0,
			searchUserName: '',
			userData: [],
			allUserList: [],
			unfoldImg:
				'https://yilife-oss-dev-public.oss-cn-hangzhou.aliyuncs.com/34/130655/ORG/c5v2sunwmc096qxe68y3tpchq.png?timestamp=1689389368891',
			packUpImg:
				'https://yilife-oss-dev-public.oss-cn-hangzhou.aliyuncs.com/34/130655/ORG/gjn3ym7bvff5afwg593pxtox3.png?timestamp=1689389346050',
			nowDateStr: '',
			periodStr: '',
			unfoldStatic: true,
			unfoldAllImg:
				'https://yilife-oss-dev-public.oss-cn-hangzhou.aliyuncs.com/34/130655/ORG/yvs1y8xeg4mrmyubv4w2w6t6p.png?timestamp=1689404068618',
			packUpAllImg:
				'https://yilife-oss-dev-public.oss-cn-hangzhou.aliyuncs.com/34/130655/ORG/pn2k1id4b0d8yz1tnpkld17gr.png?timestamp=1689404119710',
			showAll: true,
		}
	},
	onLoad(options) {
		console.log(options)
		this.detailType = options.type || 'detail'
		this.reportId = options.id || ''
		if (this.detailType === 'preview') {
			this.isPreview = true
			uni.setNavigationBarTitle({
				title: '预览',
			})
		}
		if (options.userName) {
			uni.setNavigationBarTitle({
				title: options.userName + '的' + options.typeName,
			})
		}
		this.loginUser = uni.getStorageSync('loginUser')
		this.userId = uni.getStorageSync('userId')
	},
	onShow() {
		this.initData()
	},
	computed: {
		showBottom() {
			return (
				this.detailType === 'preview' ||
				this.detailInfo.userId === this.userId
			)
		},
		//是否可回复
		showApproval() {
			return this.detailType === 'approval'
		},
	},
	methods: {
		showAllClick(val) {
			this.detailInfo.details.forEach((item) => {
				this.$set(item, 'unfold', val)
			})
			this.unfoldStatic = val
			this.showAll = val
		},
		unfoldImgClick(index, val) {
			this.detailInfo.details.forEach((item, indexC) => {
				if (indexC === index) {
					this.$set(item, 'unfold', val)
				}
			})
		},
		//添加成员
		addUser(type) {
			this.searchUserName = ''
			this.chooseUserType = type
			this.getUserData(() => {
				this.$refs.userRefs.init()
			})
		},
		//查询成员信息
		getUserData(func) {
			let _that = this
			this.$request
				.request(
					'carer-platform/journal/workJournalTemplate/userList',
					{
						data: {
							id: this.detailInfo.templateId,
							userType: this.chooseUserType,
							userName: this.searchUserName,
							orgId: uni.getStorageSync('orgId'),
						},
					}
				)
				.then((res) => {
					if (res.success) {
						let data = res.data
						if (data) {
							if (_that.chooseUserType === 0) {
								data = data.filter(
									(item) =>
										item.id !== uni.getStorageSync('userId')
								)
							}
							if (
								_that.chooseUserType === 0 &&
								_that.detailInfo.viewerUsers.length
							) {
								data.forEach((item) => {
									_that.$set(item, 'showFlag', false)
									let chooseUser =
										_that.detailInfo.viewerUsers.find(
											(res) => res.userId === item.id
										)
									if (chooseUser) {
										item.showFlag = true
									}
								})
							}
							if (
								_that.chooseUserType === 1 &&
								_that.detailInfo.auditorUsers.length
							) {
								data.forEach((item) => {
									_that.$set(item, 'showFlag', false)
									let chooseUser =
										_that.detailInfo.auditorUsers.find(
											(res) => res.userId === item.id
										)
									if (chooseUser) {
										item.showFlag = true
									}
								})
							}
						}
						if (!_that.searchUserName) {
							_that.allUserList =
								JSON.parse(JSON.stringify(data)) || []
						}
						_that.userData = data || []
						func && func()
					}
				})
		},
		//搜索
		searchUserList(data) {
			this.searchUserName = data
			this.getUserData()
		},
		//更新成员
		updateUserList(data) {
			let index = data.index
			if (this.allUserList && this.allUserList.length) {
				let allIndex = this.allUserList.findIndex(
					(res) => res.id === data.id
				)
				this.allUserList[allIndex].showFlag =
					!this.allUserList[allIndex].showFlag
			}
			this.userData[index].showFlag = !this.userData[index].showFlag
			this.$set(this.userData, index, this.userData[index])
			let userList = []
			this.allUserList.forEach((item) => {
				if (item.showFlag) {
					userList.push({
						type: this.chooseUserType,
						userId: item.id,
						userName: item.name,
					})
				}
			})
			if (this.chooseUserType === 1) {
				this.detailInfo.auditorUsers = userList
			} else {
				userList.unshift({
					type: this.chooseUserType,
					userId: this.loginUser.id,
					userName: this.loginUser.name,
				})
				this.detailInfo.viewerUsers = userList
			}
			if (this.detailInfo.auditorFlag && !this.showBottom) {
				this.submitSave(1)
				console.log(33333)
			}
			// this.autoSave()
		},
		goViewSchedule() {
			const { id, endTime, beginTime } = this.detailInfo
			uni.navigateTo({
				url:
					'/subPackagesLog/pages/workLog/viewSchedule?&journalId=' +
					id +
					'&endDate=' +
					endTime +
					'&startDate=' +
					beginTime,
			})
		},
		//数据初始化
		initData() {
			if (this.detailType === 'preview') {
				this.detailInfo = uni.getStorageSync('reportData')
				let detailsList = this.detailInfo.details
				if (detailsList && detailsList.length > 0) {
					detailsList.forEach((item) => {
						let selectLabelList = []
						if (item.labelIds && item.labelIds.length) {
							item.labelIds.forEach((tag) => {
								let tagInfo = item.workContentLabelVOList.find(
									(res) => res.labelId === tag
								)
								if (tagInfo) {
									selectLabelList.push({
										id: tagInfo.labelId,
										labelType: tagInfo.labelType,
										labelName: tagInfo.labelName,
										templateDetailId:
											tagInfo.templateDetailId,
									})
								}
							})
							item.selectedWorkContentLabelVOList =
								selectLabelList
						}
						if (item.content) {
							this.recognitionContent(item.content, (arr) => {
								if (arr && arr.length) {
									this.$set(item, 'recongtionContent', arr)
								}
							})
						}
					})
				}
				this.$set(
					this.detailInfo,
					'voices',
					this.detailInfo.voice || []
				)
			} else if (this.reportId) {
				this.getReportDetail()
			}
		},
		//查询汇报详情
		getReportDetail(index) {
			let _that = this
			this.$request
				.request('carer-platform/journal/workJournal/detail', {
					data: {
						id: this.reportId,
					},
				})
				.then((res) => {
					if (res.success) {
						_that.detailInfo = res.data
						const reportType = res.data.type + 1
						this.nowDateStr =
							reportType === 1
								? '今日'
								: reportType === 2
								? '本周'
								: '本月'
						this.periodStr =
							reportType === 1
								? '18点-今日18点'
								: reportType === 2
								? '前一周的周日的18点-本周的周日18点'
								: '前一月的最后一天的18点-本月的最后一天18点'
						let dailyDateStr = ''
						if (res.data && res.data.id) {
							if (res.data.type === 0) {
								dailyDateStr = res.data.beginTime.replace(
									/-/g,
									'/'
								)
							}
							if (res.data.type === 1) {
								dailyDateStr =
									res.data.beginTime.replace(/-/g, '/') +
									'~' +
									res.data.endTime.replace(/-/g, '/')
							}
							if (res.data.type === 2) {
								dailyDateStr =
									res.data.beginTime
										.slice(0, 7)
										.replace(/-/g, '/') + '月'
							}
							_that.$set(
								_that.detailInfo,
								'dailyDateStr',
								dailyDateStr
							)
							if (
								_that.detailInfo.details &&
								_that.detailInfo.details.length
							) {
								_that.detailInfo.details.forEach(
									(item, indexC) => {
										_that.$set(item, 'showReply', false)
										_that.$set(item, 'replyTitle', '回复')
										_that.$set(item, 'showApproval', false)
										_that.$set(
											item,
											'likeNumColor',
											item.likeStatus ? '#3a9bff' : ''
										)
										_that.$set(item, 'voice', item.voices)
										if (index === indexC) {
											_that.$set(item, 'unfold', true)
										} else {
											_that.$set(item, 'unfold', true)
										}
										if (item.content) {
											_that.recognitionContent(
												item.content,
												(arr) => {
													if (arr && arr.length) {
														_that.$set(
															item,
															'recongtionContent',
															arr
														)
													}
												}
											)
										}
									}
								)
							}
							_that.$set(
								_that.detailInfo,
								'auditorUsers',
								res.data.auditorUser
							)
							_that.$set(
								_that.detailInfo,
								'viewerUsers',
								res.data.viewerUser
							)
						}
					}
				})
		},
		//点击查看回复
		clickShowReply(index) {
			this.detailInfo.details[index].showReply =
				!this.detailInfo.details[index].showReply
			this.detailInfo.details[index].replyTitle = this.detailInfo.details[
				index
			].showReply
				? '收起回复'
				: '查看回复'
		},
		//点击回复
		clickReply(index) {
			if (this.detailInfo.readStatus !== 3) {
				this.detailInfo.details[index].showApproval =
					!this.detailInfo.details[index].showApproval
				if (this.detailInfo.details[index].showApproval) {
					this.replyData = {
						journalDetailId: '',
						content: '',
						voiceUrl: '',
						voiceDuration: 0,
						voiceText: '',
					}
					this.detailInfo.details.forEach((item, i) => {
						if (i !== index) {
							item.showApproval = false
						}
					})
				}
			}
		},
		//点赞
		clickLikeNum(item, index) {
			let _that = this
			if (this.detailInfo.readStatus !== 3) {
				this.$request
					.request(
						'carer-platform/journal/workJournalDetail/updateLikeStatus',
						{
							method: 'post',
							data: {
								journalDetailId: item.id,
								likeStatus: !item.likeStatus,
							},
						}
					)
					.then((res) => {
						if (res.success) {
							_that.detailInfo.details[index].likeStatus =
								!item.likeStatus
							let likeNum =
								_that.detailInfo.details[index].likeNum
							_that.detailInfo.details[index].likeNum = _that
								.detailInfo.details[index].likeStatus
								? likeNum + 1
								: likeNum - 1
						}
					})
			}
		},
		//弱爆
		updateWeekStatusNum(item, index) {
			let _that = this
			this.$request
				.request(
					'carer-platform/journal/workJournalDetail/updateWeekStatus',
					{
						method: 'post',
						data: {
							journalDetailId: item.id,
							weekStatus: !item.weekStatus,
						},
					}
				)
				.then((res) => {
					if (res.success) {
						_that.detailInfo.details[index].weekStatus =
							!item.weekStatus
						let weekNum = _that.detailInfo.details[index].weekNum
						_that.detailInfo.details[index].weekNum = _that
							.detailInfo.details[index].weekStatus
							? weekNum + 1
							: weekNum - 1
					}
				})
		},
		//返回修改
		backModify() {
			uni.navigateBack({
				delta: 1,
			})
		},
		//确认提交
		submitSave(type) {
			let _that = this
			this.isDisabled = true
			this.$request
				.request('carer-platform/journal/workJournal/save', {
					method: 'post',
					data: this.detailInfo,
				})
				.then((res) => {
					if (res.success) {
						uni.removeStorageSync('reportData')
						if (type != 1) {
							uni.showToast({
								title: '操作成功',
								icon: 'success',
							})
							setTimeout(() => {
								uni.navigateBack({
									delta: type,
								})
							}, 1500)
						}
					} else {
						_that.isDisabled = false
					}
				})
		},
		//去修改
		goModifyReport() {
			uni.navigateTo({
				url:
					'/subPackagesLog/pages/workLog/addReport?reportId=' +
					this.reportId +
					'&reportType=' +
					(parseInt(this.detailInfo.type) + 1) +
					'&typeId=' +
					this.detailInfo.templateId +
					'&staticStart=' +
					this.detailInfo.beginTime +
					'&staticEnd=' +
					this.detailInfo.endTime,
			})
		},
		//回复输入
		replyInput(data) {
			this.replyData.content = data
		},
		//语音输入
		replyRecord(data) {
			if (data && data.filePath) {
				this.replyData.voiceUrl = data.filePath
				this.replyData.voiceDuration = data.time
				this.replyData.voiceText = data.voiceText
			} else {
				this.replyData.voiceUrl = ''
				this.replyData.voiceDuration = 0
				this.replyData.voiceText = ''
			}
		},
		//提交回复
		submitReply(item, index) {
			let _that = this
			this.replyData.journalDetailId = item.id
			if (!this.replyData.content && !this.replyData.voiceUrl) {
				uni.showToast({
					title: '回复文字或语音必填一项',
					icon: 'none',
				})
				return false
			}
			console.log(this.replyData)
			this.$request
				.request('carer-platform/journal/workJournalDetail/reply', {
					method: 'post',
					data: this.replyData,
				})
				.then((res) => {
					if (res.success) {
						uni.showToast({
							title: '操作成功',
							icon: 'success',
						})
						_that.getReportDetail(index)
					}
				})
		},
		//匹配识别文字
		async recognitionContent(inputText, func) {
			let _that = this
			await this.$request
				.request('carer-platform/content/handle/content', {
					method: 'post',
					data: {
						content: inputText,
					},
				})
				.then((res) => {
					if (res.success && res.data) {
						let newInputText = res.data.split('\n').join('<br/>')
						const results = HtmlToJson(
							newInputText,
							_that.startHandler,
							_that.endHandler,
							this
						)
						func && func(results.nodes)
					}
				})
		},
		//点击标蓝文字
		clickInfo(text, dailyId, journalDetailId) {
			let date = new Date().getTime()
			uni.navigateTo({
				url:
					'/subPackagesLog/pages/workLog/schedule/create?date=' +
					date +
					'&type=1&text=' +
					text +
					'&dailyId=' +
					dailyId +
					'&journalDetailId=' +
					journalDetailId,
			})
		},
	},
}
</script>

<style scoped lang="scss">
.pb-none {
	padding-bottom: 0 !important;
}
.container {
	background-color: #ffffff;
	min-height: calc(100vh - 160rpx);
	font-size: 32rpx;
	padding-bottom: 160rpx;
	padding-left: 0 !important;
	padding-right: 0 !important;
	.box-bd {
		border: 2rpx #dddddd solid;
		border-radius: 10rpx;
		padding: 0;
	}
	.nav-tag {
		flex: 1;
		margin-left: 10rpx;
		margin-right: 10rpx;
		height: 60rpx;
		line-height: 60rpx;
		font-size: 32rpx;
	}
	.reply-avatar {
		margin-top: 10rpx;
		width: 82rpx;
		height: 82rpx;
		border-radius: 41rpx;
		overflow: hidden;
		display: flex;
		align-items: center;
		justify-content: center;
		text-align: center;
		background-color: #ffffff;
	}
	.avatar-img {
		width: 82rpx;
		height: 82rpx;
		border-radius: 41rpx;
	}
	.tag-view {
		border: 2rpx $tag-color solid;
		border-radius: 10rpx;
		text-align: center;
		height: 54rpx;
		line-height: 54rpx;
		padding: 0 10rpx;
		color: $tag-color;
		font-size: 28rpx;
	}
	.tag-view-active {
		border: 2rpx $active-color solid;
		color: $active-color;
		background-color: #f1f8ff;
	}
	.line-font {
		color: $primary-color;
		text-decoration: underline;
	}
	.icon-detail {
		width: 30rpx;
		height: 32rpx;
	}
	.tag-add {
		width: 174rpx;
		height: 54rpx;
		line-height: 54rpx;
		border: 2rpx $tag-color solid;
		border-radius: 10rpx;
		text-align: center;
		padding: 2rpx;
		color: $tag-color;
		font-size: 28rpx;
	}
	.qus-title {
		width: calc(100vw - 174rpx);
	}
	.reply-back {
		background-color: #eeeeee;
		border-radius: 10rpx;
		padding: 30rpx 20rpx;
	}
	.detail-box {
		background-color: #eeeeee;
		border-radius: 10rpx;
		padding: 20rpx;
	}
	.reply-line {
		border-bottom: 2rpx #f4f4f4 solid;
	}
	.top-line {
		border-top: 2rpx #eaeaea solid;
	}
	.rp-time {
		color: #a9a9a9;
	}
	.reply-button {
		height: 56rpx;
		line-height: 56rpx;
		background: linear-gradient(90deg, #2e95ff 0%, $blue-color 100%);
		font-size: 26rpx;
		color: #ffffff;
		border-radius: 40rpx;
	}
	.reply-button::after {
		border: none;
	}
	.zan-img {
		width: 34rpx;
		height: 32rpx;
	}
}
.back-c6 {
	background: $blue-color;
}
.border-4 {
	border-radius: 4rpx;
}
.w-flex {
	width: calc(100vw - 160rpx);
}
.pack-img {
	width: 160rpx;
	height: 50rpx;
}
.show-more {
	width: 272rpx;
	height: 50rpx;
}
</style>
